package org.shs.waste.dao;

import static org.shs.common.config.SystemInitializer.sqlHandler;

import java.util.ArrayList;

import org.shs.waste.form.WasteTypeForm;
import org.shs.waste.model.WasteTypeModel;

/**
 * Implementation of Database related operations for the Waste module
 * <br/>
 * <br/><b>Created:</b>&nbsp;&nbsp; 19-Nov-2008 23:55:17
 *
 * @author anirvan
 *
 */
public class WasteDAOImpl implements IWasteDAO
{
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#getWasteTypes(java.lang.String)
    */
   @SuppressWarnings("unchecked")
   public ArrayList<WasteTypeModel> getWasteTypes(String wasteTypeDesc) 
   throws Exception
   {
      ArrayList<WasteTypeModel> wasteTypes = null;
      
      //Fire the query to retrieve the list of waste types
      wasteTypes = (ArrayList<WasteTypeModel>)sqlHandler.queryForList(
                                                         "Waste.getWasteTypes", 
                                                         wasteTypeDesc);
      
      return wasteTypes;
   }
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#getWasteTypeDetails(java.lang.String)
    */
   public WasteTypeModel getWasteTypeDetails(String wasteTypeId) 
   throws Exception
   {
      WasteTypeModel wasteType = null;
      
      //Fire the query to retrieve the waste type details.
      wasteType = (WasteTypeModel)sqlHandler.queryForObject(
                                                   "Waste.getWasteTypeDetails", 
                                                   wasteTypeId);
      
      return wasteType;
   }
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#getAggrWasteTypes()
    */
   @SuppressWarnings("unchecked")
   public ArrayList<WasteTypeModel> getAggrWasteTypes() throws Exception
   {
      ArrayList<WasteTypeModel> aggrWasteTypes = null;
      
      //Fire the query to retrieve the list of waste types
      aggrWasteTypes = (ArrayList<WasteTypeModel>)sqlHandler.queryForList(
                                                "Waste.getAggrWasteTypeList");
      
      return aggrWasteTypes;
   }
   
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#addWasteTypeData(
    *    org.shs.waste.form.WasteTypeForm)
    */
   public String addWasteTypeData(WasteTypeForm wasteTypeData) throws Exception
   {
      String wasteTypeId = null;
      
      // Inserts details for a new waste type
      wasteTypeId = (String) sqlHandler.insert("Waste.addWasteTypeData", 
                                               wasteTypeData);
      
      return wasteTypeId;
   }
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#addWasteTypeHistData(
    *    org.shs.waste.form.WasteTypeForm)
    */
   public void addWasteTypeHistData(WasteTypeForm wasteTypeData) 
   throws Exception
   {
      // Inserts details for a new waste type
      sqlHandler.insert("Waste.addWasteTypeHistData", wasteTypeData);
   }
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#editWasteTypeData(
    *    org.shs.waste.form.WasteTypeForm)
    */
   public void editWasteTypeData(WasteTypeForm wasteTypeData) throws Exception
   {
      // Updates details for a waste type
      sqlHandler.update("Waste.editWasteTypeData", wasteTypeData);
   }
   
   /* (non-Javadoc)
    * @see org.shs.waste.dao.IWasteDAO#delWasteTypeData(java.lang.String)
    */
   public void delWasteTypeData(String wasteTypeId) throws Exception
   {
      // delete details for a waste type
      sqlHandler.delete("Waste.delWasteTypeData", wasteTypeId);
   }
}
